package leetcode.链表;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 小峰
 * Date: 2019-10-25
 * Time: 9:25
 * Url:https://leetcode-cn.com/problems/reverse-linked-list/
 */
public class _206_反转链表 {

    public ListNode reverseList(ListNode head) {
        if(head==null ||head.next ==null){
            return head;
        }
        ListNode listNode = reverseList(head.next);
        head.next.next=head;
        head.next=null;
        return listNode;
    }

    public ListNode reverseList1(ListNode head) {
        ListNode newHead=null;
        while (head !=null){
            ListNode tem=head;
            head=head.next;
            tem.next=newHead;
            newHead=tem;
        }
        return newHead;
    }
}
